package sort;

import java.util.Arrays;

public class InsertSort {
    public static void main(String[] args) {
        int[] arrays = new int[]{3,2,9,1};
        Arrays.stream(arrays).forEach(System.out::println);
        System.out.println("==============================");
        insert(arrays);
        Arrays.stream(arrays).forEach(System.out::println);
    }

    public static  void insert(int[] array){
        if(array.length <= 1){
            return;
        }
        for(int i = 1; i< array.length; i++){
            int value = array[i];
            int j = i - 1;
            for(;j >= 0; j--){
                if(array[j] > value){
                    array[j + 1] = array[j];
                }else{
                    break;
                }
            }
            array[j+1] = value;
        }
    }
}
